const jwt = require('jsonwebtoken');
// jwt sign  verify
module.exports = (opt) => {
  return async (ctx, next) => {
    const { authorization = '' } = ctx.header;
    // 错误处理
    try {
      const user = jwt.verify(authorization, ctx.app.config.keys)
      ctx.state.user = user;
      await next()
    } catch (err) {
      ctx.body = {
        code: -1,
        msg: err.message
      }
    }
  }
}